

		**********************************************************
		** File: 1_cleaning_for_irt.do							**
		** Paper: Human Trafficking Indicators: A New Dataset	**
		** Author: Richard Frank								**
		** Date: July 11, 2021									**
		** Task: Cleaning HTI data for IRT models				**
 		**********************************************************
	
	
	capture log close
	version 16.1
	set seed 1234

	log using HT_irt.log, replace
	set scheme  lean1 
	set more off
			
	cd 	"~"
	
	use "HTI 00-17.dta", clear
	
	** Keeping relevant variables **
	
	keep country ccode year destination pdest ldest ddest dsdest cpdest cldest

	** getting rid of non-states (e.g. Macau and Hong Kong)	
	drop if ccode<0
	
	** Collapsing no and no mention **
	
		codebook dest /* 0 cases */
		codebook ldest  /* 3 cases */
		replace ldest=0 if ldest==-1
		codebook pdest
		replace pdest=0 if pdest==-1 /* 1 cases */		
		codebook cldest /* 2 cases */
		replace cldest=0 if cldest==-1 
		codebook ddest /* 0 cases */
		codebook dsdest /* 1 cases */
		replace dsdest=0 if dsdest==-1
			
		codebook cpdest  /* 712 missing cases; 1=-1*/
		replace cpdest=0 if cpdest==.
		replace cpdest=0 if cpdest==-1
		
		codebook country ccode year  destination pdest ldest ddest cpdest cldest

		** stripping out value labels **	
		gen s=0 if dest==0
		replace s=1 if dest==1
		corr s dest
		drop dest
		rename s dest
		
		gen ps=0 if pdest==0
		replace ps=1 if pdest==1
		corr ps pdest
		drop pdest
		rename ps pdest	
		 
		gen ls=0 if ldest==0
		replace ls=1 if ldest==1
		corr ls ldest
		drop ldest
		rename ls ldest				 
		 
		gen ds=0 if ddest==0
		replace ds=1 if ddest==1
		corr ds ddest
		drop ddest
		rename ds ddest			 
		 
		gen dss=0 if dsdest==0
		replace dss=1 if dsdest==1
		corr dss dsdest
		drop dsdest
		rename dss dsdest		 
		
		gen cps=0 if cpdest==0
		replace cps=1 if cpdest==1
		corr cps cpdest
		drop cpdest
		rename cps cpdest
		
		gen cls=0 if cldest==0
		replace cls=1 if cldest==1
		corr cls cldest
		drop cldest
		rename cls cldest		
		
		
		** merging UNODC and IOM data **
		
		merge 1:1  ccode year using"UNODC_detect_traf_03_17.dta"
		drop _merge
		
		merge 1:1 ccode year using "/Users/rich/Dropbox/Data/HT/CTDC/data/CTDC_2020_dest_cyr.dta"
		
		drop if year==2018
		drop if ccode==.
		drop _merge
		drop CTDC
		
		** coarsen the UNODC and CTDC into quartiles **
		xtile u_vict_5 = UNODC_v, nq(5)
		xtile c_labor_5 = labo, nq(5)
		xtile c_sex_5 = sex, nq(5)
		xtile c_vic_5 = vict, nq(5)
		
		drop UNODC_victims labour_ctdc sex_ctdc victims_ctdc
		
		* adding 1's to each variable so Stan will start w/1
		replace dest=dest+1
		replace pdest=pdest+1
		replace ldest=ldest+1		
		replace ddest=ddest+1		
		replace dsdest=dsdest+1
		replace cpdest=cpdest+1		
		replace cldest=cldest+1		
		
 
		** putting in NAs so that R will match style of this to previous work
		tostring dest pdest ldest ddest dsdest cpdest cldest u_vict_5 c_sex_5 c_labor_5 c_vic_5 , replace
		
		replace dest="NA" if dest=="."
		replace pdest="NA" if pdest=="."
		replace ldest="NA" if ldest=="."		
		replace ddest="NA" if ddest=="."		
		replace dsdest="NA" if dsdest=="."
		replace cpdest="NA" if cpdest=="."		
		replace cldest="NA" if cldest=="."		
		replace u_vict_5="NA" if u_vict_5=="."		
		replace c_labor_5="NA" if c_labor_5=="."		
		replace c_sex_5="NA" if c_sex_5=="."		
		replace c_vic_5="NA" if c_vic_5=="."		
		
		export delimited using "HT_irt_merged1.csv", replace
		
		save "hti_irt_merged.dta", replace
		
		log close
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
